/**
 * Creater with IntelliJ IDEA.
 * Description:
 * User: 86152
 * Dae: 2022-08-01
 * Time: 18:35
 */
public class demo2 {
    public static void main(String[] args) {
        Object o1 = new Object();
        Object o2 = new Object();
        Thread t1 = new Thread() {
            public void run() {
                synchronized (o1) {
                    try {
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o2) {
                        System.out.println(1);
                    }
                }
            }
        };
        Thread t2 = new Thread() {
            public void run() {
                synchronized (o2) {
                    try {
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (o1) {
                        System.out.println(2);
                    }
                }
            }
        };
        t1.start();
        t2.start();
    }
}
